var util=require("util")
var async=require("async")
var _=require("underscore")
var _s=require("underscore.string")
var ObjectID=require("mongodb").ObjectID
$load("MyUtil.js")
var path=require("path")
var arrRoutes=[
    ["post","","$auth","$form","$isObjectBody",submitOneDonation],
    ["get","detail/:_id_donation","$auth","$params",queryOneDonation],
    ["get","sync/:page/:perpage","$filter","$params",syncDonations],
    ["get","usages/:_id_donation/:page/:perpage","$filter","$params",syncDonationUsages]
]

function DonationController(arrRoutes,strRoutePrefix,strViewPrefix,strSubApp){
    Controller.call(this,arrRoutes,strRoutePrefix,strViewPrefix,strSubApp)
}
util.inherits(DonationController,Controller)

function submitOneDonation(req,res,next){
    var objForm=req.form
    objForm["_id_publish_user"]=req.ocid
    $dao["donation"].insertOneDonation(objForm,_.bind(res.reply,res))
}

function queryOneDonation(req,res,next){
    $dao["donation"].detailOneDonation(req.params["_id_donation"],_.bind(res.reply,res))
}

function syncDonations(req,res,next){
    $dao["donation"]["syncDonations"](req.params["page"],req.params["perpage"],req.filter,req.sort,_.bind(res.reply,res))
}

function syncDonationUsages(req,res,next){
    $dao["donation"]["syncDonationUsages"](req.params["_id_donation"],req.params["page"],req.params["perpage"],req.filter,req.sort,_.bind(res.reply,res))
}

module.exports=new DonationController(arrRoutes,"donation","donation","")